package org.sagitta.httprpc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public final class ApplicationContext {
	static private ApplicationContext instance;
	static private Object lockObj = new Object(); 
	
	private ThreadLocal<HttpSession> session;
	private ThreadLocal<HttpServletRequest> httpRequest;
	
	private ApplicationContext() {
		session = new ThreadLocal<HttpSession>();
		httpRequest = new ThreadLocal<HttpServletRequest>();
	}
	
	static public ApplicationContext getInstance() {
		synchronized (lockObj) {
			if (instance == null) {
				instance = new ApplicationContext();
			}
		}
		return instance;
	}

	public HttpSession getSession() {
		return session.get();
	}

	public void setSession(HttpSession session) {
		this.session.set(session);
	}

	public HttpServletRequest getHttpRequest() {
		return httpRequest.get();
	}

	public void setHttpRequest(HttpServletRequest httpRequest) {
		this.httpRequest.set(httpRequest);
	}
}
